<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('盘点计划')" />

<link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/css/font/iconfont.css}" media="all"/>
<link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/js/layui/css/layui.css}" media="all"/>
<link rel="stylesheet" type="text/css" th:href="@{/css/main.css}" media="all"/>

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <input type="hidden" th:value="${pdhbid}" id="pdhbid" name="pdhbid">
                </form>
                <!--列表-->
                <section class="panel panel-padding layui-card-body" >
                    <div class="pro">
                        <table id="table"  class="table text-nowrap" style="word-break:break-all; word-wrap:break-word;"></table>
                    </div>
                </section>

                <div class="group-button" style="float:right;margin-bottom: 10px">
                    <a class="layui-btn layui-btn-sm layui-btn-normal save">
                        <i class="layui-icon">&#x1005;</i> 保存
                    </a>
                    <a class="layui-btn layui-btn-sm layui-btn-normal closes">
                        <i class="layui-icon">&#x1005;</i> 取消
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>


<div style="padding: 0px 15px;" hidden="hidden" id="xuanzeDiv">
    <div class="layui-fluid larry-wrapper">
        <div class="layui-row layui-col-space30">
     <div class="layui-col-xs24">
         <section class="panel panel-padding">
             <form id="form1"  action="">
                 &nbsp;
               <div class="layui-form-item">
                     <label class="layui-form-label">人员</label>
                     <div class="layui-input-block">
                        <!-- <input type="text" name="zyryid"  id="zyryid" required="required" jq-verify="required" jq-error="请输入人员" lay-verify="required" placeholder="操作人员" autocomplete="off" class="layui-input "/>&ndash;&gt;-->
                         <select lay-ignore="lay-ignore" class="zyryid" id="zyryid" name="zyryid"   select2  onchange="getName()"  style="width: 193px" ></select>
                         </select>
                     </div>
                 </div>
                 <input type="hidden" id="zyrymc" name="zyrymc">
             </form>
         </section>
     </div>
 </div>
    </div>
</div>



</body>


<script type="text/javascript" th:src="@{/plugin/layui/js/layui/layui.js}"></script>
<script type="text/javascript" th:src="@{/plugin/layui/js/version.js}"></script>
<script th:src="@{/plugin/layui/js/common.js}"></script>
<div th:include="public/public_js::public_js"></div>
<style type="text/css">

</style>
<script>
    //	回车查询
    document.onkeydown = function(event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            //执行的方法
            $('#search_button').click();
        }
    };
    layui.use(['list','layer','zzpUtils','jquery','laydate'],function () {
        window.operateEvent = {
            //预检
            "click .xuanze": function (e, value, row, index) {//增加地址
                console.info("增加地址");
                xuanze(row.id,index);
            },

            "change .pdsl":function (e, value, row, index) {//盘点数量更改时
                var reg = /^([1-9]\d*|[0]{1,1})$/;//包含0 的正整数
            if(!$("#pdsl"+row.id).val().match(reg)){
                layer.msg("请输入正整数！");
                $("#pdsl"+row.id).val("1");
            }else{
                row.pdsl=$("#pdsl"+row.id).val();
                $table.bootstrapTable('updateRow', {index:index,row:row});
            }
        },
        }
            var zzpUtils= layui.zzpUtils,
            $ = layui.jquery,
            layer=layui.layer,
            laydate = layui.laydate;

        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination:true,
            url: '/wmsinventoryplan/getStockPlan',
            columns: [{
                field: '',
                checkbox: true
            },{
                field: 'asnbh',
                title: 'ASN编号',
                width: 200
            },{
                field: 'goodsBh',
                title: '货品编号',
                width:200
            },{
                field: 'goodsMc',
                title: '货品名称',
                width:200
            },{
                field: 'hppc',
                title: '货品批次'
            },{
                field: 'scrq',
                title: '生产日期'
            },{
                field: 'rksj',
                title: '入库时间'
            },{
                field: 'pdsl',
                title: '盘点数量',
                formatter: operateFormatterNumber,
                events:operateEvent
            },{
                field: 'zyryId',
                title: '作业人员'
            },{
                field: 'sxrq',
                title: '失效日期'
            },{
                field: 'gysmc',
                title: '供应商名称'
            },{
                field: 'kwmc',
                title: '库位名称'
            },{
                field: 'jhsl',
                title: '计划数量'
            },{
                field: 'show_cyzt',
                title: '差异状态'
            },{
                field:'caozuo',
                title: '可用操作',
                events:operateEvent,
                formatter:operateFormatter
            }],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (row,index) {
                return "这里就没有确定过11";
            },
            /*onDblClickRow:function (row,index) {//双击展示

            }*/

        });



        function operateFormatter(value, row, index) {
            return [
                '<a class="layui-btn layui-btn-xs layui-btn-radius layui-btn-warm  xuanze" >选择</a>'

            ].join('')
        }
        function operateFormatterNumber (value,row,index) {
            return [
                '<input type="number" class="layui-input pdsl" id="pdsl'+row.id+'" value="'+ value +'"  name="pdsl"  step="1"   style="width:80px;    height: 30px;"/>'
               /* '<input type="text" id="pdsl'+row.id+'"  name="pdsl" value="'+ value +'" style="width:80px;"/>',*/
            ].join('')
        }
        $(".inline-search-btn").on('click',function () {
            zzpUtils.refreshTable("#table");
        });

       /* $("#zyryid").select2({
            placeholder : "请输入查询字段", //默认文本框显示信息
            minimumInputLength : 1, //最小输入字符长度
            allowClear : true,
            multiple : false, //设置多项选择，false则只能单选
            maximumSelectionSize : 5, //最大选择个数
            query : function(query) {
                $.ajax({
                    type : "POST",
                    //url : "insti.do?method=getCurrent",
                    url: "/zxsswms/wmsqualityinspectionlist/selectYh",
                    data : {
                        name : query.term
                    }, //传递你输入框中的值
                    success : function(msg) {
                        var msg = $.parseJSON(msg);
                        var data = {
                            results : []
                        };
                        $.each(msg, function(x, y) {
                            data.results.push({
                                id : y.id,
                                text : y.name
                            });
                            ;
                        });
                        query.callback(data);
                    }
                });
            }
        });*/

        $('#zyryid').select2({
            ajax: {
                url: "/zxsswms/wmsqualityinspectionlist/selectYh",
                dataType: 'json',
                type: 'POST',
                contentType: "application/json",
                data: function (params) {
                    var query = {
                        name: params.term
                    };
                    return JSON.stringify(query);
                },
                processResults: function (data) {
                    console.info(data);
                    var arr = new Array();
                    if (data) {
                        for (var i = 0; i < data.length; i++) {
                            arr.push({id: data[i].id, text: data[i].name});
                        }
                    }
                    console.info("arr");
                    console.info(arr);
                    return {
                        results: arr
                    };
                },
                cache: true
            },
            language: "zh-CN",
            placeholder: '请输入查询字段',
            allowClear: true

        });

        window.getName=function(){
            $("#zyrymc").val($("#zyryid").select2("data")[0].text);
        }
         var xuanzeIndex="";
        function xuanze(id,index){
            xuanzeIndex=index;
            layer.open({
                type: 1,
                title: "选择",
                content: $("#xuanzeDiv"),
                shade: [0.4, '#393D49'],
                area: ['70%', '50%'],
                success: function(layero, index){
                }
                ,btn: ['保存','关闭']
                ,yes: function(index, layero){
                    var tabledata = $table.bootstrapTable('getData');
                    var zyryid=$("#zyryid").val();
                    if(zyryid==null||zyryid==""){
                      layer.msg("请完整信息");
                    }else {
                        var formObject = {};
                        var formArray = $("#form1").serializeArray();
                        $.each(formArray, function (i, item) {
                            formObject[item.name] = item.value;
                        });
                        console.info(formObject);
                        var row = tabledata[xuanzeIndex];
                        console.info(row);
                        row.pdsl = $("#pdsl" + row.id).val();
                        row.zyryId = formObject.zyrymc;
                        row.zyrymc = formObject.zyrymc;
                        console.info(formObject);
                        console.info(row);
                        $table.bootstrapTable('updateRow', {index: xuanzeIndex, row: row});
                        $table.bootstrapTable('load', tabledata);
                        layer.close(index);
                    }
                }
                ,btn2 : function (index, layero) {
                    layer.close(index);
                }
            })
        }






        //保存
        $(".save").on('click',function () {
            var rows = $table.bootstrapTable('getSelections');
            if(rows.length == 0){
                layer.msg("请至少选择一条");
            }else{
                for(var i=0;i<rows.length;i++){
                    rows[i].pdsl=$("#pdsl"+rows[i].id).val();
                }
                console.info(rows);
                zzpUtils.confirm("是否确定保存", function (index) {
                    zzpUtils.action({
                        url: "/wmsinventoryplan/addStockPlan",
                        data: JSON.stringify(rows),
                        success: function (data) {
                            setTimeout(function () {
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                                console.info(data);
                                top.layer.msg(data.title + "," + data.message);
                                //刷新父页面
                                parent.location.reload();
                            }, 500);
                        }, error: function (xhr, textStatus) {
                            console.log(textStatus);
                            console.log(xhr)
                        }
                    })
                })
            }
        })
        $(".closes").on('click',function () {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        })


        //保存选择
        $(".saveXuanzea").on('click',function () {

            var tabledata = $table.bootstrapTable('getData');
            var formObject={};
            var formArray =$("#form1").serializeArray();
            $.each(formArray,function(i,item){
                formObject[item.name] = item.value;
            });
           var row= tabledata[xuanzeIndex];
            row.zyryId=formObject.zyryid;
            row.zyrymc=formObject.zyrymc;
            console.info(formObject);
            console.info(row);
            $table.bootstrapTable('updateRow', {index: xuanzeIndex, row: row});
            $table.bootstrapTable('load', tabledata);
            layer.close(xuanzeIndex);

        })


    });


</script>
</html>